﻿Imports System.Data.OleDb

Module Mod_DataHander
    Dim m_ModName As String = "modDataHandler"

    Private Function GetCon() As OleDbConnection
        Dim reportPath As String = Application.StartupPath & "\db\InsightDB.mdb"
        Dim ConStr As String = "provider=SQLOLEDB;SERVER=127.0.01;uid=sa;pwd=sa4321;database=MASICDB"
        Dim con As OleDbConnection = New OleDbConnection(ConStr)
        Return con
    End Function

    Public Function execSQLQueryNoResult(ByVal sqlStr As String) As Boolean
        Dim funName As String = "exeSQLQueryNoResult"
        Dim result As Boolean = False
        Try
            Dim oleconn As OleDbConnection = GetCon()
            If (oleconn.State = ConnectionState.Closed) Then
                oleconn.Open()
            End If
            Dim command As New OleDbCommand(sqlStr, oleconn)
            Dim i = command.ExecuteNonQuery()
            If (i = 0) Then
                result = False
            Else
                result = True
            End If
            If (oleconn.State = ConnectionState.Open) Then
                oleconn.Close()
            End If
        Catch ex As Exception
            ErrInfoHandle(m_ModName, funName, ex.Message, ex.Source)
        End Try
        Return result
    End Function

    Public Function execSQLQuery(ByVal sqlStr As String) As DataTable
        Dim funName As String = "execSQLQuery"
        Try
            Dim oleconn As OleDbConnection = GetCon()
            If (oleconn.State = ConnectionState.Closed) Then
                oleconn.Open()
            End If
            Dim dataadpter As New OleDbDataAdapter(sqlStr, oleconn)
            Dim dataset As New DataSet
            dataadpter.Fill(dataset, "PicInfo")
            If (dataset.Tables("PicInfo").Rows.Count > 0) Then
                Return dataset.Tables("PicInfo")
            Else
                Return Nothing
            End If
            If (oleconn.State = ConnectionState.Open) Then
                oleconn.Close()
            End If
        Catch ex As Exception
            ErrInfoHandle(m_ModName, funName, ex.Message, ex.Source)
        End Try
        Return Nothing
    End Function

    Public Function AdjustLineDateSame() As Boolean
        If (struplcdate.Equals(Nothing) And struformdate.Equals(Nothing)) Then
            Return True
        ElseIf (struplcdate.Equals(Nothing) Or struformdate.Equals(Nothing)) Then
            Return False
        ElseIf (struplcdate.lineid <> struformdate.lineid Or struplcdate.stackno <> struformdate.stackno Or struplcdate.stacknum <> struformdate.stacknum Or struplcdate.producesum <> struformdate.producesum Or struplcdate.badpartnum <> struformdate.badpartnum) Then
            Return False
        Else
            Return True
        End If
    End Function
End Module
